@echo off
cls

rem %1 = database server name
rem %2 = database name

@echo on

@echo ********************************************************************************
@echo Creating supporting procedures...
@echo off
rem Always drop and re-create these in case they have been updated in source control
osql -S %1 -b -E -n -d master -i "..\Security\sp_KillDbProcesses.sql"
rem if ERRORLEVEL 1 exit 1
osql -S %1 -b -E -n -d master -i "..\Security\sp_AddWindowsUserLogin.sql"
rem if ERRORLEVEL 1 exit 1
osql -S %1 -b -E -n -d master -i "..\Security\sp_AddSqlUserLogin.sql"
rem if ERRORLEVEL 1 exit 1
osql -S %1 -b -E -n -d master -i "..\Security\sp_SetStoredProcedurePermissions.sql"
rem if ERRORLEVEL 1 exit 1
@echo on
@echo ********************************************************************************

@echo.

@echo ********************************************************************************
@echo Creating NavigantPortal database...
@echo off
osql -S %1 -b -E -n -d master -i "..\Database Creation\NavigantPortalDbCreate.sql"
rem if ERRORLEVEL 1 exit 1
@echo on
@echo ********************************************************************************

@echo.

@echo ********************************************************************************
@echo Creating NavigantPortal logins and roles...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\Security\NavigantPortalDbLogins.sql"
rem if ERRORLEVEL 1 exit 1
@echo on
@echo ********************************************************************************

@echo.

@echo ********************************************************************************
@echo Creating NavigantPortal tables, primary keys, and foreign keys...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\Table Creation\NavigantPortalDbTables.sql"
rem if ERRORLEVEL 1 exit 1
@echo on
@echo ********************************************************************************

@echo.

@echo ********************************************************************************
@echo Populating NavigantPortal table lookup data...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\Data Population\NavigantPortalLookupTables.sql"
rem if ERRORLEVEL 1 exit 1
@echo on
@echo ********************************************************************************

@echo.

@echo off
osql -S %1 -b -E -n -d %2 -i "..\Table Creation\CaseSiteMapping.sql"
@echo on
@echo ********************************************************************************

@echo.

@echo ********************************************************************************
@echo Adding the NewSiteID and NewSiteUrl columns to NavigantPortal tables...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\ChangeScripts\AddNewSiteID.sql"
@echo on
@echo ********************************************************************************

@echo.

@echo Creating NavigantPortal Case Site Mapping stored procedures...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\CaseSiteMigration.sql"
@echo on

@echo.

@echo ********************************************************************************
@echo Creating NavigantPortal stored procedures...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SendNoticeQueueInsert.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SendNoticeQueueGetAll.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SendNoticeQueueDelete.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SendNoticeHistoryInsert.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetBySite.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetBySiteCollection.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetBySiteCustodian.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetBySiteNoticeCustodian.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryInsert.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryInsertNew.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryUpdateAcknowledgement.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\UrlDictionaryEntryGet.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\UrlDictionaryEntryCreate.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetUnconfirmed.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetUnconfirmedByNewSite.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryUpdateSent.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryUpdateTries.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryAttachmentInsert.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByNoticeID.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetBySitePaged.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByNewSitePaged.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByNewSite.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByNewSiteCustodian.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByNewSiteNoticeCustodian.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByID.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\PreservationNoticeHistoryGetByIdentifier.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SmtpLogEntryGet.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SmtpLogEntryGetWithAllCodes.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SendNoticeQueueGetOne.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\SendNoticeQueueGetOneNewSite.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\InetLogUpdatePreservationNoticeHistoryID.sql"
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueGetByID.sql
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueDelete.sql
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueInsert.sql
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueUpdate.sql
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueItemInsert.sql
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueItemUpdate.sql
osql -S %1 -b -E -n -d %2 -i "..\Stored Procedures\RemindersQueueGetBySiteCollectionID.sql
rem if ERRORLEVEL 1 exit 1

@echo on
@echo ********************************************************************************

@echo.

@echo ********************************************************************************
@echo Setting permissions on NavigantPortal stored procedures...
@echo off
osql -S %1 -b -E -n -d %2 -i "..\Security\StoredProcedurePermissions.sql"
rem if ERRORLEVEL 1 exit 1
@echo on
@echo ********************************************************************************

@echo.

@echo off


pause

